<include file="Public:header" />
<include file="Public:leftside" />
<style type="text/css">
	.modal {
	    height: 600px;
	   
	}
	.modal-infp-style {
		width: 90%;
		margin: 10px auto;
	}
	
	.modal-infp-style table {
		width: 100%;
	}
	
	.modal-infp-style table tr td {
		border: 1px solid #e6e6e6;
		padding: 8px;
	}
	
	a:hover {
		cursor: pointer;
	}
</style>
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
				<a href="/">首页</a>
			</li>
			<li class="active">会员管理</li>
		</ul>
	</div>
	<section class="scrollable wrapper">
		
		<!-- 操作提示  start -->
		<!-- 操作提示  end -->

		<div class="row padder-v">
			<div class="col-sm-9" style="width:74%;">
				<a href="javascript:;" class="btn btn-sm btn-primary" onclick="add_user();"><i class="fa fa-plus"></i> 添加会员 </a>
			</div>
			
		</div>
		<section class="panel panel-default">
			<div class="table-responsive">
				<table class="table table-striped b-t b-light text-sm">
					<thead>
						<tr>
							<th>登录账号</th>
							<th class="center">所属用户组</th>
							<th class="center">状态</th>
							<th class="center">操作</th>
						</tr>
					</thead>
					<tbody id="list">
						
						<foreach name="user_list" item="v">
							<tr align="center">
								<td align="left">
									{$v.user_name}
								</td>
								<td class="tal">管理员组</td>
								<td style="color:green;">
									<eq name="v.ishidden" value="0">启用</eq>
									<eq name="v.ishidden" value="1">禁用</eq>
								</td>
								<td>
									<a onclick="modify_password({$v.id})">重置密码</a> <neq name="v['id']" value="1">| <a href="{:U('users/authority',array('id'=>$v['id']))}">权限配置</a></neq>
								</td>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>

			<footer class="panel-footer">
				<div class="row" id="page">
				<div class="col-sm-2 text-center">
						<small class="text-muted inline m-tb-8">总计 <span id="total_count_num">{$count}</span>个记录</small>
					</div>
					<div class="col-sm-5 text-right text-center-xs">
						<ul class="pagination pagination-sm m-t-none m-b-none">
							{$page}
						</ul>
					</div>
				</div>
			</footer>

		</section>

		<script type="text/javascript">
			

			/**
			重置密码弹出
			*/
			function modify_password(uid) {
				$("#modify_password").modal("show");
				$("#modify_userid").val(uid);
			}
			/**
			修改密码提交
			*/
			function modifypassword() {
				var uid = $("#modify_userid").val();
				var password = $("#modify_passwords").val();
				if(password == null || password.length < 6) {
					
					layer.msg('密码必须不小于6位！')
					return false;
				}
				$.ajax({
					type: "post",
					url: "{:U('users/updatememberpassword_admin')}",
					data: {
						'uid': uid,
						'user_password': password
					},
					success: function(data) {
						if(data['code'] == 0) {
							layer.msg('无数据更新！')
						} 
						if(data['code'] == 1) {
							layer.msg('修改成功！');
							setTimeout("location.reload()",1000);
						} 
					}
				});
			}
			//添加会员弹出
			function add_user() {
				$("#add_user").modal("show");
			}
			//添加会员
			function addUser() {
				var username = $("#username").val();
				var password = $("#password").val();
				var nickname = $("#nickname").val();
				var level_name = $("#member_level").val();
				var status = $("input[name='status']:checked").val();

				if(username == '') {
					layer.msg('手机不能为空')
					return;
				}

				if(!checkUserName(username)) {
					layer.msg('用户已存在')
					return;
				}
				//检测输入的会员用户名是否已经存在
				$("#username").blur(function() {
					var username = $(this).val();
					$(this).css("border", "1px solid #ccc");
					$("#usernameyz").css("color", "black").text("");
					$("#isset_username").attr("value", "不存在");
					if(username === $("#modify_username_hidden").val()) {
						return;
					}
					checkUserName(username);
				});

				function checkUserName(username) {
					var flag = true;
					$.ajax({
						type: "GET",
						url: "{:U('users/check_username_admin')}",
						async: false,
						data: {
							"username": username
						},
						success: function(data) {
							if(data.code==1) {
								flag = false;
								$("#username").css("border", "1px solid red");
								$("#usernameyz").css("color", "red").text("用户名已存在");
								$("#isset_username").attr("value", "存在");
							}
						}
					});
					return flag;
				}
				if(password == null || password.length < 6) {
					layer.msg('密码必须不小于6位！')
					return;
				}
				if(username.length > 0) {
					if(!(/^1(3|4|5|7|8)\d{9}$/.test(username))) {
						layer.msg('手机号码有误，请重填！')
						return;
					}
				}
				
				$.ajax({
					type: "post",
					url: "{:U('users/addmember_admin')}",
					data: {
						'user_name': username,
						'password': password,
						'nickname':nickname,
						'user_level': level_name,
						'ishidden': status
					},
					success: function(data) {
						if(data['code'] == 0) {
							layer.msg('用户添加失败！')
						} 
						if(data['code'] == 1) {
							layer.msg('用户添加成功！');
							//setTimeout("location.reload()",1000);
						} 
						if(data['code'] == 2) {
							layer.msg('该用户已存在！')
						} 
					}
				});

			}
		</script>
		

		<!-- 添加会员 -->
		<div class="modal" id="add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title" id="myModalLabel">添加会员</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style" style="height:260px;overflow:auto;">
							<table class="modal-tab">
								<tbody>
									<tr>
										<td style="width:20%;"><span class="required">*</span>手机号码</td>
										<td colspan="3">
											<input type="text" id="username">
											<span id="usernameyz"></span>
										
										</td>
									</tr>
									<tr>
										<td><span class="required">*</span>登录密码</td>
										<td colspan="3"><input type="password" id="password" class="balance"></td>
									</tr>
									<tr>
										<td style="width:22%;">昵称</td>
										<td colspan="3">
											<input type="text" id="nickname">
										</td>
									</tr>
									<tr>
										<td>管理等级</td>
										<td colspan="3">
											<p>
												<select id="member_level">
													<option value="1">管理员组</option>
												</select>
											</p>
										</td>
									</tr>
									
									<tr>
										<td>账户状态</td>
										<td>
											<label><input type="radio" checked="checked" name="status" value="0">正常&nbsp;&nbsp;</label>
											<label><input name="status" type="radio" value="1">锁定</label>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<button class="btn btn-info" onclick="addUser()" id="butSubmit" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>
		<input type="hidden" id="modify_uid">

		
		<!-- 修改会员 -->
		<div class="modal" id="modify_password" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title" id="myModalLabel">重置密码</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style">
							<table class="modal-tab">
								<tbody>
									<tr>
										<td style="width:20%">密码</td>
										<td colspan="3"><input type="text" id="modify_passwords"></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<input type="hidden" id="modify_userid">
						<button class="btn btn-info" onclick="modifypassword()" id="butSubmit" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>

	</section>
</div>

<include file="Public:footer" />